/**
 * 发送部分在这里
 * Created by hello world on 2016/12/8.
 */

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Email {
    private static final String host="smtp.sina.com";
    private static final String home_address="latimer1101@sina.com";
    private static final String password="gxy961101";

    public static void sendMail(String target_address){
        Properties props=System.getProperties();
        props.put("mail.smtp.host",host);
        props.put("mail.smtp.auth","true");
        Session session=Session.getDefaultInstance(props, new Authenticator() {
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(home_address, password);
            }
        });

        try{
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(home_address));
            message.addRecipient(Message.RecipientType.TO,new InternetAddress(target_address));
            message.setSubject("Java");
            message.setText("Do you like me?");
            Transport.send(message);
        }catch (MessageRemovedException e){
            e.printStackTrace();
        }catch (Exception e){
            System.out.print("发生了什么");
        }
    }





    public static void main(String[] args){
        Email.sendMail("wlmqjiyizh@163.com");
    }
}
